package com.spring.boot.test.config.stragegy;


import com.spring.boot.test.utils.StrUtils;

import java.util.zip.CRC32;

public abstract class ModCodeFieldShardStrategy implements FieldShardStrategy{
    abstract int getShardNum();

    @Override
    public String getShardSuffix(String shardingValue) {
        CRC32 crc32 = new CRC32();
        crc32.update(StrUtils.getContentBytesByUTF8(shardingValue));
        String value = String.valueOf(crc32.getValue());
        return StrUtils.tail3(StrUtils.getModuloValue(Long.parseLong(StrUtils.tail3(value)), this.getShardNum()));
    }
}
